<?php header('Access-Control-Allow-Origin: *'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Sample Page</title>
    <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
    
    <script type="text/javascript">

        function LoadAdditionalData() {
            //create the queryUrl to be used in the service call
            var query = "http://servico.dados.gov.pt/v1/gepe/Alunos20072008?format=json";
            var filter = "";
            var queryUrl = query + filter;

            //make jquery call to service
            $.getJSON(queryUrl, null, AdditionalData_Loaded);
        }

        //callback method
        function AdditionalData_Loaded(data) {
            //create a table
            var placeholder = document.getElementById("myTablePlaceholder");
            var table = document.createElement('TABLE');
            var tbdy = document.createElement('TBODY');
            table.appendChild(tbdy);

            //for each row in the table add the cell contents
            for (var i = 1; i < data.d.length; i++) {
                var tr = document.createElement('TR');
                tbdy.appendChild(tr);
                tr.appendChild(AddCellContents(data.d, i, 'dre'));
                tr.appendChild(AddCellContents(data.d, i, 'concelho'));
                tr.appendChild(AddCellContents(data.d, i, 'total'));
                tr.appendChild(AddCellContents(data.d, i, 'educacaopreescolar'));
                tr.appendChild(AddCellContents(data.d, i, 'total1ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'regular1ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'artisticoespecializadoregimeintegrado1ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'cursosefa1ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'total2ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'regular2ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'artisticoespecializadoregimeintegrado2ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'cursoscef2ciclo'));
                tr.appendChild(AddCellContents(data.d, i, 'recorrente2ciclo'));
            }
            //add the table to page
            placeholder.appendChild(table);
        }

        //add cell contents to the table
        function AddCellContents(data, cell, id) {
            var td = document.createElement('TD');
            var dataCell = data[cell][id];
            td.appendChild(document.createTextNode(dataCell));
            return td;
        }
        
    </script>

</head>

<body>
    <a href="#" onclick="LoadAdditionalData();">Listar Estatisticas de Alunos 2007-2008</a>
    <div id ="myTablePlaceholder"></div>
    <div id ="myTablePlaceholder2"></div>
</body>
</html>